package com.wgq.uitest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.wgq.uitest.exp6.UdpServer;

/**
 * 服务器端界面
 */
public class Main5Activity extends AppCompatActivity {

    TextView main_content;
    Handler handler;
    Button to_ClientActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main5);

        main_content = findViewById(R.id.main_content);
        to_ClientActivity = (Button) findViewById(R.id.btn_to_client);

        to_ClientActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Main5Activity.this, Main52Activity.class);
                startActivity(intent);
            }
        });

        handler = new Handler(){
            @Override
            public void handleMessage(Message msg) {
                if(msg.what == 0x1234){
                    main_content.setText(main_content.getText().toString() + msg.getData().getString("content"));
                }
            }
        };
        new Thread(new UdpServer(handler)).start();
    }
}